﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoogleGeocode
{
    public class Country
    {
        public Country(address_component component)
        {
            this.Short = component.short_name;
            this.Long = component.long_name;
        }
        public Country() { }
        public string Short { get; set; }
        public string Long { get; set; }
    }

    public class Area
    {
        public Area(address_component component)
        {
            this.Short = component.short_name;
            this.Long = component.long_name;
        }
        public Area() { }
        public string Short { get; set; }
        public string Long { get; set; }
    }

    public class City
    {
        public City(address_component component)
        {
            this.Short = component.short_name;
            this.Long = component.long_name;
        }
        public City() { }
        public string Short { get; set; }
        public string Long { get; set; }
    }

    public class District
    {
        public District(address_component component)
        {
            this.Short = component.short_name;
            this.Long = component.long_name;
        }
        public District() { }
        public string Short { get; set; }
        public string Long { get; set; }
    }

    public class Route
    {
        public Route(address_component component)
        {
            this.Short = component.short_name;
            this.Long = component.long_name;
        }
        public Route() { }
        public string Short { get; set; }
        public string Long { get; set; }
    }

    public class StreetAddress
    {
        public StreetAddress(address_component component)
        {
            this.Short = component.short_name;
            this.Long = component.long_name;
        }
        public StreetAddress() { }
        public string Short { get; set; }
        public string Long { get; set; }
    }

    public class GoogleGeocodeResponse
    {
        public GoogleGeocodeResponse(RawResponse response)
        {
            this.Areas = new List<Area>();
            this.Districts = new List<District>();

            foreach (var component in response.results[0].address_components)
            {
                switch (component.types[0])
                {
                    case "country":
                        {
                            this.Country = new Country(component);
                            break;
                        }
                    case "administrative_area_level_1":
                    case "administrative_area_level_2":
                    case "administrative_area_level_3":
                    case "administrative_area_level_4":
                    case "administrative_area_level_5":
                    case "administrative_area_level_6":
                    case "administrative_area_level_7":
                        {
                            this.Areas.Add(new Area(component));
                            break;
                        }
                    case "locality":
                        {
                            this.City = new City(component);
                            break;
                        }
                    case "sublocality_level_1":
                    case "sublocality_level_2":
                    case "sublocality_level_3":
                    case "sublocality_level_4":
                    case "sublocality_level_5":
                    case "sublocality_level_6":
                    case "sublocality_level_7":
                        {
                            this.Districts.Add(new District(component));
                            break;
                        }
                    case "route":
                        {
                            this.Route = new Route(component);
                            break;
                        }
                    case "street_number":
                        {
                            this.StreetAddress = new StreetAddress(component);
                            break;
                        }
                }
            }
        }

        public Country Country { get; set; }
        public List<Area> Areas { get; set; }
        public City City { get; set; }
        public List<District> Districts { get; set; }
        public Route Route { get; set; }
        public StreetAddress StreetAddress { get; set; }
    }
}
